package eu.webhib.extgui.controller.intf;

import eu.webhib.extgui.data.intf.GuiBaseEntity;

/**
 * Interface to provide required data to the edit controller managing the edit dialog
 */
public interface EditDataProvider<T extends GuiBaseEntity> {

   T getNewEntity();

   /**
    * Retrieve the data entity to be edited in the edit dialog
    * Called when the edit dialog is opened after activation (e.g. Edit-button is clicked)
    * @return entity used in dialog to be edited
    */
   T getEntityToEdit();

   /**
    * Hands over the changed entity from the edit dialog
    * Called after the Save-button is clicked in the edit dialog
    * @param changedEntity
    * @return whether the verification of the changed entity succeeds
    */
   boolean verifyEntity(T changedEntity);

   public void relationsChanged();

   /**
    * Is called to check if the current entity may be deleted. If it shall not be deleted
    * a error message has to be set on the given edit controller.
    * @return entity allowed to be deleted, null if not (when an error message was set)
    */
   T getEntityToDelete();

   /**
    * Is called after positive confirmation, the entity has to be deleted from the data store
    * @param entityToDelete the entity to be deleted
    */
   void performDeletion(T entityToDelete);
}
